#include "BufferReader.h"

BufferReader::BufferReader(unsigned char *buffer, uint32_t bufferLen) {
	this->buffer = buffer;
	this->length = bufferLen;
	this->pos = 0;
}

int8_t BufferReader::getByte() {
	int8_t val = (*(int8_t *)(buffer + pos));
	pos++;
	return val;
}

int8_t BufferReader::getByte(int32_t pos) {
	return (*(int8_t *)(buffer + pos));
}

int16_t BufferReader::getShort() {
	int16_t val = (*(int16_t *)(buffer + pos));
	pos += 2;
	return val;
}

int16_t BufferReader::getShort(int32_t pos) {
	return (*(int16_t *)(buffer + pos));
}

int32_t BufferReader::getInt() {
	int32_t val = (*(int32_t *)(buffer + pos));
	pos += 4;
	return val;
}

int32_t BufferReader::getInt(int32_t pos) {
	return (*(int32_t *)(buffer + pos));
}

int64_t BufferReader::getLong() {
	int64_t val = (*(int64_t *)(buffer + pos));
	pos += 8;
	return val;
}

int64_t BufferReader::getLong(int32_t pos) {
	return (*(int64_t *)(buffer + pos));
}

string BufferReader::getString() {
	int16_t len = getShort();
	string stri((char *) buffer + pos, len);
	pos += len;
	return stri;
}

string BufferReader::getString(int32_t pos) {
	int16_t len = getShort();
	string stri((char *) buffer + pos, len);
	pos += len;
	return stri;
}

double BufferReader::getDouble() {
	double dbl = (*(double *)(buffer + pos));
	pos += 8;
	return dbl;
}

double BufferReader::getDouble(int32_t pos) {
	return (*(double *)(buffer + pos));
}
